package me.magicall.db.sql.table;

import me.magicall.db.sql.Domain;
import me.magicall.db.sql.Domainable;
import me.magicall.db.sql.NamedElement;

/**
 * 带有域前缀的sql元素(父类)。如table、column
 * 
 * @author MaGiCalL
 */
public abstract class AbsDomainable<D extends Domain> extends NamedElement implements Domainable<D> {

	private D domain;

	protected AbsDomainable() {
		super();
	}

	protected AbsDomainable(final String name) {
		super(name);
	}

	protected AbsDomainable(final String name, final D domain) {
		super(name);
		setDomain(domain);
	}

	@Override
	public StringBuilder appendTo(final StringBuilder sb) {
		sb.append(" ");
		final Domain domain = getDomain();
		if (domain != null) {
			domain.appendTo(sb).append(".");
		}
		return sb.append(getName()).append(" ");
	}

	public D getDomain() {
		return domain;
	}

	public void setDomain(final D domain) {
		this.domain = domain;
	}
}